package com.xuecheng.manage_cms_client.mq;

import com.alibaba.fastjson.JSON;
import com.xuecheng.manage_cms_client.dao.CmsPageRepository;
import com.xuecheng.manage_cms_client.service.PageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class PostPageConsumer {
    private static final Logger LOGGER = LoggerFactory.getLogger(PostPageConsumer.class);

    @Autowired
    private CmsPageRepository cmsPageRepository;

    @Autowired
    private PageService pageService;

    @RabbitListener(queues="${xuecheng.mq.queue}")
    public void postPage(String msg){
        //获取页面id
        Map map = JSON.parseObject(msg, Map.class);
        LOGGER.info("receive post page: " + map.toString());

        String pageId = (String) map.get("pageId");
        //保存页面到服务器物理路径
        pageService.savePageToServerPath(pageId);
    }

}
